package com.czxy.demo17;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test01 {
    public static void main(String[] args) {
        Student s1=new Student("zhangsan",18,"男");
        Student s2=new Student("lihong",22,"女");
        Student s3=new Student("wangwu",19,"男");
        Student s4=new Student("wuwu",8,"女");
        Student s5=new Student("lilin",35,"男");

        List<Student> list=new ArrayList<Student>();
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);
        list.add(s5);
        show01(list);
        show02(list);
    }
    public static void show01(List<Student>list){
        int countnan=0;
        int countnv=0;
        Map<String,Integer>map=new HashMap<>();
        for (Student stu : list) {
            if("男".equals(stu.getSex())){
                countnan++;
                map.put("男",countnan);
            }
            if("女".equals(stu.getSex())){
                countnv++;
                map.put("女",countnv);
            }
        }
        for (String key : map.keySet()) {
            System.out.println(key+"("+map.get(key)+")");
        }
    }
    public static void show02(List<Student>list){
        Map<String,Integer>map=new HashMap<>();
        int countChen=0;
        int countWei=0;
        for (Student stu : list) {
            if(stu.getAge()>=18){
                countChen++;
                map.put("成年",countChen);
            }
            if(stu.getAge()<18){
                countWei++;
                map.put("未成年",countWei);
            }
        }
        for (String key : map.keySet()) {
            System.out.println("key="+key+" value="+map.get(key));
        }
    }
}
